import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/pages/match/match_controller.dart';
import 'package:flutter_changdian_football/pages/match/widget/enrollment_widget.dart';
import 'package:flutter_changdian_football/pages/match/widget/to_be_widget.dart';
import 'package:flutter_changdian_football/widget/screenutil/custom_screenutil.dart';
import 'package:flutter_changdian_football/widget/wd_underline_tab_indicator.dart';
import 'package:get/get.dart';

/// 比赛
class MatchPage extends StatefulWidget {
  const MatchPage({super.key});

  @override
  State<MatchPage> createState() => _MatchPageState();
}

class _MatchPageState extends State<MatchPage> with AutomaticKeepAliveClientMixin {

  @override
  bool get wantKeepAlive => true;

  @override
  Widget build(BuildContext context) {
    super.build(context);
    
    return Scaffold(
      backgroundColor: const Color(0xffF8FAF9),
      body: GetBuilder<MatchController>(
        init: MatchController(),
        builder: (matchController) {
          return Stack(
            children: [
              Container(
                width: double.infinity,
                height: double.infinity,
                decoration: const BoxDecoration(
                  gradient: LinearGradient(
                    begin: Alignment.topCenter,
                    end: Alignment.bottomCenter,
                    stops: [0, 0.2, 0.4, 1.0],
                    colors: [
                      Color(0xff49935E),
                      Color(0xff4EAE6B),
                      Color(0xffF8FAF9),
                      Color(0xffF8FAF9)
                    ]
                  )
                ),
                child: Column(
                  children: [
                    SafeArea(
                      child: _tabbarTabWidget(matchController),
                    ),

                    Expanded(
                      child: SizedBox(
                        child: TabBarView(
                          controller: matchController.tabController,
                          physics: const BouncingScrollPhysics(),
                          children: [
                            EnrollmentWidget(),
                            ToBeWidget(),
                          ],
                        ),
                      ),
                    )
                  ],
                ),
              )
            ],
          );
        },
      ),
    );
  }

  _tabbarTabWidget(MatchController matchController) {
    return Stack(
      children: [
        SizedBox(
          width: double.infinity,
          child: TabBar(
            labelColor: const Color(0xffEDFFF3),
            controller: matchController.tabController,
            isScrollable: false,
            indicatorSize: TabBarIndicatorSize.label,
            // indicator: GradientTabIndicator(),
            indicator: WDUnderlineTabIndicator(
              customWidth: 20.w,
              borderSide: BorderSide(width: 4.w, color: Colors.white),
            ),
            labelPadding: EdgeInsets.symmetric(horizontal: 15.w),
            indicatorPadding: EdgeInsets.symmetric(vertical: 5.w),
            labelStyle: TextStyle(color: const Color(0xffEDFFF3), fontSize: 17.sp, fontWeight: FontWeight.w500),
            unselectedLabelStyle: TextStyle(color: const Color(0xffA2DBB4), fontSize: 17.sp, fontWeight: FontWeight.w500),
            tabs: [
              Tab(text: '报名中${matchController.signingMatchNum == null ? '' : '(${matchController.signingMatchNum})'}'),
              Tab(text: '待开始${matchController.waitForStartMatchNum == null ? '' : '(${matchController.waitForStartMatchNum})'}')
            ],
          ),
        ),
      ],
    );
  }


}